public class OptimalDivision {

    public static void main(String[] args) {
        int[] nums = {1000, 100, 10, 2};
        System.out.println(new OptimalDivision().optimalDivision(nums));
    }

    public String optimalDivision(int[] nums) {
        double[] sum = new double[nums.length];
        double temp = nums[0];
        sum[0] = temp;
        for (int i = 1; i < nums.length; i++) {
            temp /= nums[i];
            sum[i] = temp;
        }
        double res = Integer.MIN_VALUE;
        int l = 0;
        int r = 0;
        for (int i = 1; i < nums.length - 1; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                double a = nums[i];
                for (int k = i + 1; k <= j; k++) {
                    a /= nums[k];
                }
                if (j < nums.length - 1) {
                    double b = nums[j + 1];
                    for (int k = j + 2; k < nums.length; k++) {
                        b /= nums[k];
                    }
                    temp = sum[i - 1] / a / b;
                } else temp = sum[i - 1] / a;
                if (temp > res) {
                    res = temp;
                    l = i;
                    r = j;
                }
            }
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < nums.length; i++) {
            if (i == l && l != 0) stringBuilder.append("(");
            stringBuilder.append(nums[i]);
            if (i == r && l != 0) stringBuilder.append(")");
            if (i != nums.length - 1) stringBuilder.append("/");
        }
        return stringBuilder.toString();
    }
}
